package com.ruoyi.app.util.secure;


import com.ruoyi.app.util.basecommon.BaseSecure;
import com.ruoyi.app.util.basecommon.SecureType;

import java.security.NoSuchAlgorithmException;

public class SecureFactory {

    public static BaseSecure getSecure(SecureType type, String key) {
        BaseSecure secure = null;
        switch (type) {
            case DES3:
                if (key != null && !"".equals(key)) {
                    secure = new DES3Secure(key);
                } else {
                    try {
                        secure = new DES3Secure();
                    } catch (NoSuchAlgorithmException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case RSA_PRIVATE:
                secure = new RSAPrivateSecure(key);
                break;
            case RSA_PUBLIC:
                secure = new RSAPublicSecure(key);
                break;
            default:
                throw new IllegalArgumentException("SecureType not be supported.");
        }
        return secure;
    }
}
